<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>销售数据管理系统</title>

    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://"
          integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

</head>
<body>

<div class="container my-2">
    <h1>销售数据列表</h1>

    <a th:href="@{/showNewSaleForm}" class="btn btn-primary btn-sm mb-3"> 添加销售数据 </a>

    <table border="1" class="table table-striped table-responsive-md">
        <thead>
        <tr>
            <th>
                <a th:href="@{'/page/' + ${currentPage} + '?sortField=id&sortDir=' + ${reverseSortDir}}">ID</a>
            </th>
            <th>
                <a th:href="@{'/page/' + ${currentPage} + '?sortField=customerName&sortDir=' + ${reverseSortDir}}">顾客名称</a>
            </th>
            <th>
                <a th:href="@{'/page/' + ${currentPage} + '?sortField=quantity&sortDir=' + ${reverseSortDir}}">销售数量</a>
            </th>
            <th>
                <a th:href="@{'/page/' + ${currentPage} + '?sortField=totalAmount&sortDir=' + ${reverseSortDir}}">销售总金额</a>
            </th>
            <th>
                <a th:href="@{'/page/' + ${currentPage} + '?sortField=date&sortDir=' + ${reverseSortDir}}">日期</a>

            </th>
            <th> Actions</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="sale : ${listSale}">
            <td th:text="${sale.id}"></td>
            <td th:text="${sale.customerName}"></td>
            <td th:text="${sale.quantity}"></td>
            <td th:text="${sale.totalAmount}"></td>
            <td th:text="${sale.date}"></td>
            <td><a class="btn btn-primary" th:href="@{/showFormForUpdate/{id}(id=${sale.id})}">更新销售数据</a>
                <a class="btn btn-danger" th:href="@{/deleteSale/{id}(id=${sale.id})}">删除销售数据</a>
            </td>
        </tr>
        </tbody>
    </table>

    <div th:if = "${totalPages > 1}">
        <div class = "row col-sm-10">
            <div class = "col-sm-3">
                Total Rows: [[${totalItems}]]
            </div>
            <div class = "col-sm-5">
					<span th:each="i: ${#numbers.sequence(1, totalPages)}">
						<a th:if="${currentPage != i}" th:href="@{'/page/' + ${i}+ '?sortField=' + ${sortField} + '&sortDir=' + ${sortDir}}">[[${i}]]</a>
						<span th:unless="${currentPage != i}">[[${i}]]</span>  &nbsp; &nbsp;
					</span>
            </div>
            <div class = "col-sm-1">
                <a th:if="${currentPage < totalPages}" th:href="@{'/page/' + ${currentPage + 1}+ '?sortField=' + ${sortField} + '&sortDir=' + ${sortDir}}">Next</a>
                <span th:unless="${currentPage < totalPages}">Next</span>
            </div>

            <div class="col-sm-1">
                <a th:if="${currentPage < totalPages}" th:href="@{'/page/' + ${totalPages}+ '?sortField=' + ${sortField} + '&sortDir=' + ${sortDir}}">Last</a>
                <span th:unless="${currentPage < totalPages}">Last</span>
            </div>
        </div>
    </div>

</div>
</body>
</html>
